package com.example.douyin.adapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.douyin.R;
import com.example.douyin.chat.ChatEntity;
import com.hyphenate.chat.EMMessage;
import com.hyphenate.chat.EMTextMessageBody;

import java.util.List;

public class ChatAdapter extends BaseMultiItemQuickAdapter<ChatEntity, BaseViewHolder> {
    public ChatAdapter(@Nullable List<ChatEntity> data) {
        super(data);
        addItemType(0,R.layout.iten_chat_send);
        addItemType(1,R.layout.iten_chat_receive);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, ChatEntity entity) {
        if(entity.getType().equals(EMMessage.Type.TXT)){
            String message = ((EMTextMessageBody) (entity.getBody())).getMessage();
            holder.setText(R.id.tv,message);
        }else{
            holder.setText(R.id.tv,"非文本消息");
        }

    }
}
